﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;

namespace SharePointSocialNetworking.Webparts.TwitterTrendsWebPart
{
    class TwitterTrendsEditorPart:EditorPart
    {
        #region private members
        private TextBox _tbHash, _tbNum;
        private Label _lblHash, _lblNum;
        #endregion

        #region Constructor
        public TwitterTrendsEditorPart()
        {
            this.ID = "TwitterEditorPart";
            this.Title = "Twitter Settings";
        }
        #endregion

        #region overrides
        protected override void CreateChildControls()
        {
            _lblHash = new Label() { Text = "Hashtag:" };
            Controls.Add(_lblHash);

            Controls.Add(new Literal() { Text = "<br/>" });

            _tbHash = new TextBox();
            Controls.Add(_tbHash);

            Controls.Add(new Literal() { Text = "<br/><br/>" });

            _lblNum = new Label() { Text = "Number of tweets:" };
            Controls.Add(_lblNum);

            Controls.Add(new Literal() { Text = "<br/>" });

            _tbNum = new TextBox();
            Controls.Add(_tbNum);
        }

        public override bool ApplyChanges()
        {
            EnsureChildControls();
            TwitterTrendsWebPart part = (TwitterTrendsWebPart)WebPartToEdit;
            part.HashTag = _tbHash.Text;
            part.NumOfTweets = _tbNum.Text;
            return true;
        }

        public override void SyncChanges()
        {
            EnsureChildControls();
            TwitterTrendsWebPart part = (TwitterTrendsWebPart)WebPartToEdit;
            _tbHash.Text = part.HashTag;
            _tbNum.Text = part.NumOfTweets;
        }

        #endregion
    }
}
